import { MessageBox, Message } from 'element-ui'

export const defaultUtils = async (fn, params, message, msg) => {
  await MessageBox.confirm(message, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      const response = fn(params)
      response.then(res => {
        if (res.data.success) {
          Message({
            type: 'success',
            message: `${msg}成功!`
          })
        } else {
          Message({
            type: 'error',
            message: `${msg}失败!`
          })
        }
      })
    })
    .catch(() => {})
}
